package trunk.view;

import javax.swing.JFormattedTextField;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.text.MaskFormatter;

import trunk.control.UsuarioControlador;

@SuppressWarnings("serial")
public class TopPanel extends JPanel{
	private JLabel ateLabel;
	private JFormattedTextField dataFimCampo;
	private JFormattedTextField dataInicioCampo;
	private JLabel deLabel;
	private JFormattedTextField horaFimCampo;
	private JFormattedTextField horaInicioCampo;
	private JTextField tituloCampo;
	private JLabel tituloLabel;

	public TopPanel(UsuarioControlador controlador) {
		setBorder(javax.swing.BorderFactory.createEtchedBorder());

		tituloLabel = new JLabel();
		tituloLabel.setText("Título:");

		tituloCampo = new JTextField();
		tituloCampo.setToolTipText("Título do Evento");

		deLabel = new JLabel();
		deLabel.setText("de");

		ateLabel = new JLabel();
		ateLabel.setText("até");

		dataInicioCampo = new JFormattedTextField(Mascara("##/##/####"));
		dataInicioCampo.setToolTipText("dd/mm/aaaa");

		horaInicioCampo = new JFormattedTextField(Mascara("##:##"));
		horaInicioCampo.setToolTipText("hh:mm");

		dataFimCampo = new JFormattedTextField(Mascara("##/##/####"));
		dataFimCampo.setToolTipText("dd/mm/aaaa");

		horaFimCampo = new JFormattedTextField(Mascara("##:##"));
		horaFimCampo.setToolTipText("hh:mm");

		javax.swing.GroupLayout topPanelLayout = new javax.swing.GroupLayout(this);
		setLayout(topPanelLayout);
		topPanelLayout.setHorizontalGroup(
				topPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, topPanelLayout.createSequentialGroup()
						.addContainerGap()
						.addGroup(topPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
								.addGroup(javax.swing.GroupLayout.Alignment.LEADING, topPanelLayout.createSequentialGroup()
										.addComponent(tituloLabel)
										.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addComponent(tituloCampo, javax.swing.GroupLayout.DEFAULT_SIZE, 339, Short.MAX_VALUE))
										.addGroup(topPanelLayout.createSequentialGroup()
												.addComponent(deLabel)
												.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
												.addComponent(dataInicioCampo, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
												.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
												.addComponent(horaInicioCampo, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
												.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
												.addComponent(ateLabel)
												.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
												.addComponent(dataFimCampo, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
												.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
												.addComponent(horaFimCampo, javax.swing.GroupLayout.DEFAULT_SIZE, 74, Short.MAX_VALUE)))
												.addContainerGap())
		);
		topPanelLayout.setVerticalGroup(
				topPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(topPanelLayout.createSequentialGroup()
						.addContainerGap()
						.addGroup(topPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
								.addComponent(tituloCampo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
								.addComponent(tituloLabel))
								.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
								.addGroup(topPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
										.addComponent(deLabel)
										.addComponent(dataInicioCampo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
										.addComponent(horaInicioCampo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
										.addComponent(dataFimCampo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
										.addComponent(ateLabel)
										.addComponent(horaFimCampo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
										.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
		);
	}

	public void setDataFim(String dataFim) {
		this.dataFimCampo.setText(dataFim);
	}

	public void setDataInicio(String dataInicio) {
		this.dataInicioCampo.setText(dataInicio);
	}

	public void setHoraFim(String horaFim) {
		this.horaFimCampo.setText(horaFim);
	}

	public void setHoraInicio(String horaInicio) {
		this.horaInicioCampo.setText(horaInicio);
	}

	public void setTituloCampo(String titulo) {
		this.tituloCampo.setText(titulo);
	}

	public JFormattedTextField getDataFimCampo() {
		return dataFimCampo;
	}

	public JFormattedTextField getDataInicioCampo() {
		return dataInicioCampo;
	}

	public JFormattedTextField getHoraFimCampo() {
		return horaFimCampo;
	}

	public JFormattedTextField getHoraInicioCampo() {
		return horaInicioCampo;
	}

	public JTextField getTituloCampo() {
		return tituloCampo;
	}

	public static MaskFormatter Mascara(String Mascara){  

		MaskFormatter F_Mascara = new MaskFormatter();  
		try{  
			F_Mascara.setMask(Mascara); //Atribui a mascara  
			F_Mascara.setPlaceholderCharacter('_'); //Caracter para preencimento  
			F_Mascara.setValueContainsLiteralCharacters(false);  
		}  
		catch (Exception excecao) {  
			excecao.printStackTrace();  
		}  
		return F_Mascara;  
	}
}
